package com.adcc.ags.gms.mq.vo;

import com.adcc.ags.gms.core.entity.BaseEntity;
import com.adcc.ags.gms.core.vo.BaseVO;
import com.adcc.utility.mq.entity.ibm.QueueManager;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 消息管理器视图
 */
public class QMVO extends BaseVO{

    // 名称
    private String name;

    // IP
    private String ip;

    // 端口
    private int port;

    // 启动时间
    private String startTime;

    // 连接数
    private int connectCount;

    // 状态
    private String status;

    // QM连接是否溢出
    private boolean overflow;

    /**
     * 构造函数
     */
    public QMVO() {

    }

    /**
     * 构造函数
     * @param qm
     */
    public QMVO(QueueManager qm){
        if(qm != null){
            name = qm.getName();
            ip = qm.getIp();
            port = qm.getPort();
            startTime = qm.getStartTime();
            connectCount = qm.getConnectCount();
            if(qm.isStatus()){
                status = "Running";
            }else{
                status = "Stop";
            }
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public int getConnectCount() {
        return connectCount;
    }

    public void setConnectCount(int connectCount) {
        this.connectCount = connectCount;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public boolean isOverflow() {
        return overflow;
    }

    public void setOverflow(boolean overflow) {
        this.overflow = overflow;
    }

    @Override
    public BaseEntity toEntity() {
        return null;
    }

    @Override
    public String toJson() throws JsonProcessingException {
        return new ObjectMapper().writeValueAsString(this);
    }
}
